class EventEmitter {
  constructor () {
    this.subs = Object.create(null)
  }

  $on (eventType, handler) {
    this.subs[eventType] = this.subs[eventType] || []
    this.subs[eventType].push(handler)
  }

  $emit (eventType) {
    const handlers = this.subs[eventType]

    if (handlers) {
      handlers.forEach(handler => {
        handler()
      })
    }
  }
}

const em = new EventEmitter()

em.$on('click', () => console.log('click1'))
em.$on('click', () => console.log('click2'))

em.$emit('click')
